Real-Time Data Feed
Velolink provides a real-time WebSocket data feed for live usage updates. This guide will walk you through connecting to and consuming the live data feed.
Prerequisites
Before connecting to the live data feed, ensure you have:
- Your namespace identifier (found in the admin panel under your user profile)
- An API token with the
velolink.datapermission or theVelolink READ Datarole
Connection Steps
1. Obtain API Token
First, you'll need to retrieve an API token from the Velolink Console.
2. Verify Permissions
Ensure your API token has the required permissions (velolink.data) to access the data feed.
3. Connect to WebSocket
The WebSocket endpoint follows this format:
ws://feed.velolink.cloud/agents/velolink-latest-data/[namespace]
Replace [namespace] with your namespace identifier.
Include your API token in the connection headers:
const headers = {
"X-ApiToken": "your-api-token-here",
};
Example Data Structure
The WebSocket feed delivers JSON messages with the following structure:
{
"type": "cf_agent_state",
"state": {
"data": {
"915": {
"vehicleId": "915",
"namespace": "mynamespace",
"operator": "DT",
"routeId": "Green Line",
"tripId": "3732174",
"features": ["cyclist", "priority"],
"featureData": {
"cyclist": {
"deployed": true,
"capacity": 3,
"available": 2,
"used": 1,
"type": "cyclist",
"rideStart": false,
"rideEnd": false
},
"priority": {
"capacity": 2,
"available": 1,
"used": 1,
"type": "priority",
"rideStart": false,
"rideEnd": false
}
},
"lat": 37.41038131713867,
"long": -121.95980072021484,
"timestamp": "2025-04-16T15:15:53.405Z",
"events": []
}
}
}
}
Data Fields
type: Message type identifierstate.data: Object containing vehicle data, keyed by vehicle ID- For each vehicle:
vehicleId: Unique identifier for the vehiclenamespace: Organization namespaceoperator: Transit operator namerouteId: Current route identifier (may be empty string if not on route)tripId: Current trip identifier (may be empty string if not on trip)features: Array of available features (e.g., ["cyclist", "priority"])featureData: Detailed feature information:cyclist: Bicycle rack informationdeployed: Boolean indicating if rack is deployedcapacity: Total bicycle capacityavailable: Number of available spotsused: Number of spots in usetype: Feature type identifierrideStart: Boolean indicating start of riderideEnd: Boolean indicating end of ride
priority: Priority seating informationcapacity: Total priority seating capacityavailable: Number of available priority seatsused: Number of priority seats in usetype: Feature type identifierrideStart: Boolean indicating start of riderideEnd: Boolean indicating end of ride
lat: Latitude coordinatelong: Longitude coordinatetimestamp: UTC timestamp of the data pointevents: Array of recent events for the vehicle
Information Information
info
- All timestamps are in ISO 8601 format with UTC timezone
- The WebSocket connection requires a valid API token with the
velolink.datapermission - Data is streamed in real-time as vehicles update their status
- Each message contains the complete state for all vehicles in your namespace
- Vehicles may have multiple features (e.g., cyclist racks and priority seating)
- Empty route and trip IDs indicate the vehicle is not currently in service
- Feature status (deployed, rideStart, rideEnd) helps track usage patterns
Error Handling
Common WebSocket connection errors:
- 401: Invalid or missing API token
tip
It's recommended to implement reconnection logic in case of connection drops or errors.